home *** CD-ROM | disk | FTP | other *** search
/ Mac Cube 4: Multimedia Applications / MacCube Volume 4: Multimedia Applications.iso / Graphics / NIH Image Folder / Macros / Image Macros < prev    next >
Text File  |  1993-07-30  |  3KB  |  123 lines

  1. {
  2. This file contains contains example macros written in Image's
  3. Pascal-like programming language. These macros will automatically
  4. be loaded when Image is launched as long as this file is in the same folder
  5. as Image, or in the System folder, and it has the name 'Image Macros'.
  6. }
  7.  
  8. macro 'Measure [1]'       begin Measure end;
  9. macro 'Show Results [2]'  begin ShowResults end;
  10. macro 'Reset [3]'         begin ResetCounters end;
  11. macro 'Copy Results [4]'  begin CopyResults end;
  12. macro 'Start Capture [G]' begin StartCapturing end;
  13.  
  14.  
  15. Macro 'Draw Arrow [A]'
  16. {Draws an arrow based on the current straight line selection.}
  17. var
  18.   size,angle,dx,dy,pi,theta:real;
  19.   x1,y1,x2,y2,LineWidth,width,height:integer;
  20. begin
  21.   size:=12;  {pixels}
  22.   angle:=20; {degrees}
  23.   pi:=3.14159;
  24.   GetLine(x1,y1,x2,y2,LineWidth);
  25.   if x1<0 then begin
  26.     PutMessage('Use the line tool(straight) to select a line first.');
  27.     exit;
  28.   end;
  29.   MoveTo(x1,y1);
  30.   LineTo(x2,y2);
  31.   KillRoi;
  32.   GetPicSize(width,height);
  33.   y1:=height-y1;
  34.   y2:=height-y2;
  35.   if LineWidth>1 then size:=size*LineWidth*0.5;
  36.   angle:=(angle/180)*pi;
  37.   dx:=x1-x2;
  38.   dy:=y1-y2;
  39.   if dx=0 then begin
  40.     if dy>=0 then theta:=pi/2 else theta:=3/2*pi
  41.   end else begin
  42.     theta:=arctan(dy/dx);
  43.     if dx<0 then theta:=theta+pi;
  44.   end;
  45.   moveto(x2,height-y2);
  46.   lineto(x2+size*cos(theta+angle),height-(y2+size*sin(theta+angle)));
  47.   moveto(x2,height-y2);
  48.   lineto(x2+size*cos(theta-angle),height-(y2+size*sin(theta-angle)));
  49. end;
  50.  
  51.  
  52. macro 'Print All';
  53. {Use SetOption, which turns off halftoning, for better quality}
  54. {(and faster) printing of binary pictures.}
  55. var
  56.   i:integer;
  57. begin
  58.   for i:=1 to nPics do begin
  59.      SelectPic(i);
  60.      {SetOption;}
  61.      Print;
  62.   end;
  63. end;
  64.  
  65.  
  66. macro 'Clear Outside'
  67.  {Erase region outside current selection to background color.}
  68. begin
  69.   Copy;
  70.   SelectAll;
  71.   Clear;
  72.   RestoreRoi;
  73.   Paste;
  74.   KillRoi;
  75. end;
  76.  
  77.  
  78. macro 'Make Bas-relief'
  79. begin
  80.   Duplicate('Bas-relief');
  81.   SelectAll;
  82.   {SetOption; Smooth;}
  83.   Copy;
  84.   MoveRoi(-1,-1);  {Try MoveRoi(1,1) for a different effect.}
  85.   Paste;
  86.   Subtract;
  87.   EnhanceContrast;
  88.   ApplyLUT;
  89. end;
  90.  
  91.  
  92. macro '(-' begin end;
  93.  
  94.  
  95. macro 'Make Step Function';
  96. {Generates a grayscale step function within the current selection.}
  97. var
  98.   left,top,width,height,nSteps,StepSize,i,x:integer;
  99.   value:real;
  100. begin
  101.   GetRoi(left,top,Width,Height);
  102.   if width=0 then begin
  103.     PutMessage('This macro requires a rectangular selection.');
  104.     Exit;
  105.   end;
  106.   SaveState;
  107.   nSteps:=GetNumber('Number of steps',16);
  108.   value:=255;
  109.   StepSize:=width div nSteps;
  110.   x:=left;
  111.   for i:=1 to nSteps do begin
  112.     MakeRoi(x,top,StepSize,Height);
  113.     SetForeground(round(value));
  114.     fill;
  115.     x:=x+StepSize;
  116.     value:=value-256/nSteps;
  117.   end;
  118.   KillRoi;
  119.   RestoreState;
  120. end;
  121.  
  122.  
  123.